From eb9505d3ecdd05ca230a683d0b0f65ae1925597e Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Sat, 8 Oct 2005 09:54:06 +0100 Subject: [PATCH] Add one more parameter to __vmread_vcpu and clean some code. Signed-off-by: Xin Xiaohui Signed-off-by: Li Chengyuan Signed-off-by: Nakajima Jun --- xen/arch/x86/vmx.c | 12 +++++++----- xen/arch/x86/vmx_io.c | 2 +- xen/include/asm-x86/vmx.h | 30 +++++++++--------------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/xen/arch/x86/vmx.c b/xen/arch/x86/vmx.c index 0b81d09f3c..28d996e4a5 100644 --- a/xen/arch/x86/vmx.c +++ b/xen/arch/x86/vmx.c @@ -425,12 +425,13 @@ static int vmx_do_page_fault(unsigned long va, struct cpu_user_regs *regs) static void vmx_do_no_device_fault(void) { unsigned long cr0; + struct vcpu *v = current; clts(); setup_fpu(current); - __vmread_vcpu(CR0_READ_SHADOW, &cr0); + __vmread_vcpu(v, CR0_READ_SHADOW, &cr0); if (!(cr0 & X86_CR0_TS)) { - __vmread_vcpu(GUEST_CR0, &cr0); + __vmread_vcpu(v, GUEST_CR0, &cr0); cr0 &= ~X86_CR0_TS; __vmwrite(GUEST_CR0, cr0); } @@ -1347,6 +1348,7 @@ static int vmx_cr_access(unsigned long exit_qualification, struct cpu_user_regs { unsigned int gp, cr; unsigned long value; + struct vcpu *v = current; switch (exit_qualification & CONTROL_REG_ACCESS_TYPE) { case TYPE_MOV_TO_CR: @@ -1369,17 +1371,17 @@ static int vmx_cr_access(unsigned long exit_qualification, struct cpu_user_regs clts(); setup_fpu(current); - __vmread_vcpu(GUEST_CR0, &value); + __vmread_vcpu(v, GUEST_CR0, &value); value &= ~X86_CR0_TS; /* clear TS */ __vmwrite(GUEST_CR0, value); - __vmread_vcpu(CR0_READ_SHADOW, &value); + __vmread_vcpu(v, CR0_READ_SHADOW, &value); value &= ~X86_CR0_TS; /* clear TS */ __vmwrite(CR0_READ_SHADOW, value); break; case TYPE_LMSW: TRACE_VMEXIT(1,TYPE_LMSW); - __vmread_vcpu(CR0_READ_SHADOW, &value); + __vmread_vcpu(v, CR0_READ_SHADOW, &value); value = (value & ~0xF) | (((exit_qualification & LMSW_SOURCE_DATA) >> 16) & 0xF); return vmx_set_cr0(value); diff --git a/xen/arch/x86/vmx_io.c b/xen/arch/x86/vmx_io.c index 67cb7739f8..8809d21704 100644 --- a/xen/arch/x86/vmx_io.c +++ b/xen/arch/x86/vmx_io.c @@ -891,7 +891,7 @@ asmlinkage void vmx_intr_assist(void) struct vcpu *v = current; highest_vector = find_highest_pending_irq(v, &intr_type); - __vmread_vcpu(CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control); + __vmread_vcpu(v, CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control); if (highest_vector == -1) { disable_irq_window(cpu_exec_control); diff --git a/xen/include/asm-x86/vmx.h b/xen/include/asm-x86/vmx.h index cdbb5d0b3f..c1ba8fd436 100644 --- a/xen/include/asm-x86/vmx.h +++ b/xen/include/asm-x86/vmx.h @@ -314,10 +314,8 @@ static always_inline int ___vmread (const unsigned long field, void *ptr, const } -static always_inline void __vmwrite_vcpu(unsigned long field, unsigned long value) +static always_inline void __vmwrite_vcpu(struct vcpu *v, unsigned long field, unsigned long value) { - struct vcpu *v = current; - switch(field) { case CR0_READ_SHADOW: v->arch.arch_vmx.cpu_shadow_cr0 = value; @@ -334,10 +332,8 @@ static always_inline void __vmwrite_vcpu(unsigned long field, unsigned long valu } } -static always_inline void __vmread_vcpu(unsigned long field, unsigned long *value) +static always_inline void __vmread_vcpu(struct vcpu *v, unsigned long field, unsigned long *value) { - struct vcpu *v = current; - switch(field) { case CR0_READ_SHADOW: *value = v->arch.arch_vmx.cpu_shadow_cr0; @@ -352,24 +348,15 @@ static always_inline void __vmread_vcpu(unsigned long field, unsigned long *valu printk("__vmread_cpu: invalid field %lx\n", field); break; } - - /* - * __vmwrite() can be used for non-current vcpu, and it's possible that - * the vcpu field is not initialized at that case. - * - */ - if (!*value) { - __vmread(field, value); - __vmwrite_vcpu(field, *value); - } } static inline int __vmwrite (unsigned long field, unsigned long value) { unsigned long eflags; + struct vcpu *v = current; __asm__ __volatile__ ( VMWRITE_OPCODE - MODRM_EAX_ECX + MODRM_EAX_ECX : : "a" (field) , "c" (value) : "memory"); @@ -381,7 +368,7 @@ static inline int __vmwrite (unsigned long field, unsigned long value) case CR0_READ_SHADOW: case GUEST_CR0: case CPU_BASED_VM_EXEC_CONTROL: - __vmwrite_vcpu(field, value); + __vmwrite_vcpu(v, field, value); break; } @@ -437,13 +424,14 @@ static inline int __vmxon (u64 addr) static inline void vmx_stts(void) { unsigned long cr0; + struct vcpu *v = current; - __vmread_vcpu(GUEST_CR0, &cr0); + __vmread_vcpu(v, GUEST_CR0, &cr0); if (!(cr0 & X86_CR0_TS)) { __vmwrite(GUEST_CR0, cr0 | X86_CR0_TS); } - __vmread_vcpu(CR0_READ_SHADOW, &cr0); + __vmread_vcpu(v, CR0_READ_SHADOW, &cr0); if (!(cr0 & X86_CR0_TS)) __vm_set_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_NM); } @@ -453,7 +441,7 @@ static inline int vmx_paging_enabled(struct vcpu *v) { unsigned long cr0; - __vmread_vcpu(CR0_READ_SHADOW, &cr0); + __vmread_vcpu(v, CR0_READ_SHADOW, &cr0); return (cr0 & X86_CR0_PE) && (cr0 & X86_CR0_PG); } -- 2.30.2